package com.fira.api.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fira.common.core.controller.BaseController;
import com.fira.common.core.domain.AjaxResult;
import com.fira.common.core.domain.platform.vo.SysDictDataVO;
import com.fira.common.utils.StringUtils;
import com.fira.platform.service.ISysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字典相关服务
 * @author henryGui
 * @version V1.0
 * @Title: DictAndDataController
 * @Package com.fira.api.controller
 * @Description: TODO
 * @date 2021-10-09 下午2:09
 */
@Api(value="数据字典查询接口",tags={"适用前后端分离数据字典通用类"})
@Controller
@RequestMapping("/api/dict")
public class DictAndDataController extends BaseController {

    @Autowired
    private ISysDictTypeService dictTypeService;

    @ApiOperation(value="根据字典类型查询字典数据",tags={"根据字典类型查询字典数据"},notes="注意问题点：为字典类型的dict_type")
    @PostMapping("/queryDictDataByType")
    @ResponseBody
    public AjaxResult queryDictDataByType(@RequestBody String dictType)
    {
        JSONObject jsonObject= JSON.parseObject(dictType);
        List<SysDictDataVO> list = dictTypeService.selectDictDataByType(jsonObject.getString("dictType"));
        return AjaxResult.success(list);
    }

    @ApiOperation(value="根据字典类型数组查询批量字典数据",tags={"根据字典类型数组查询批量字典数据"},notes="注意问题点：为字典类型的dict_type")
    @PostMapping("/queryDictDataListByTypes")
    @ResponseBody
    public AjaxResult queryDictDataListByTypes(String[] types){
        if(types == null){
            return AjaxResult.error("参数不能为空");
        }
        return AjaxResult.success("查询成功",dictTypeService.selectDictDataListByTypes(types));
    }
}
